import { Player } from "../Player";
import { Exploit } from "./Exploit";

function tampering(): void {
  if (Player.exploits.includes(Exploit.PrototypeTampering)) return;
  // Tampering
  const a = 55;
  setInterval(function () {
    if (a.toExponential() !== "5.5e+1") {
      Player.giveExploit(Exploit.PrototypeTampering);
    }
  }, 15 * 60 * 1000); // 15 minutes
}

function timeCompression(): void {
  if (Player.exploits.includes(Exploit.TimeCompression)) return;
  // Time compression
  let last = new Date().getTime();
  function minute(): void {
    const now = new Date().getTime();
    if (now - last < 500) {
      // time has been compressed.
      Player.giveExploit(Exploit.TimeCompression);
      return;
    }
    last = now;
    window.setTimeout(minute, 1000);
  }
  window.setTimeout(minute, 1000);
}

export function startExploits(): void {
  tampering();
  timeCompression();
}
